/* 复审 */
<template lang="html">
  <Card :bordered="false">
    <p slot="title">复审</p>
    <MyTrialTab :info="info" />
    <table style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th colspan="6">
          初审修改
        </th>
      </tr>
      <tr>
        <td width="16.66%">
          修改人员
        </td>
        <td width="16.66%">
          {{info.faudit}}
        </td>
        <td width="16.66%">
          初审时间
        </td>
        <td width="16.66%">
        </td>
        <td width="16.66%">
          修改完成时间
        </td>
        <td width="16.66%">
        </td>
      </tr>
      <tr>
        <td colspan="6">
          <div style="width:99%;margin:auto;height:100%;">
            <Table border ref="selection" style="border: none" :columns="chushenColumns" :data="info.Chushen" :loading="chushenLoading"></Table>
          </div>
        </td>
      </tr>
    </table>
    <table style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th colspan="4">
          复审单
        </th>
      </tr>
      <tr>
        <td width="25%">
          复审工程师
        </td>
        <td width="25%">{{info.faudit}}</td>
        <td width="25%">
          复审时间
        </td>
        <td width="25%">
          {{this.$moment().format('YYYY-MM-DD')}}
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <div style="width:99%;margin:auto;height:100%;">
            <Table id="fushen" border ref="selection" style="border: none" :columns="fushenColumns" :data="info.Fushen"
              :loading="fushenLoading" @on-row-click="getIndex"></Table>
            <Row>
              <Col span="24" style="text-align: center;padding:10px">
              <Button type="primary" @click="inputAdd('Fushen')">添加</Button>
              <Button type="error" @click="inputRemove('Fushen')">删除</Button>
              </Col>
            </Row>
          </div>
        </td>
      </tr>
      <tr>
        <td>
          报告（正文、附图、附件、附表）
        </td>
        <td colspan="3">
          <Upload action="//jsonplaceholder.typicode.com/posts/">
            <Button>上传</Button>
          </Upload>
        </td>
      </tr>
    </table>
    <Row style="margin-top: 10px">
      <Col span="24" style="text-align:right;">
      <Button type="primary" @click="submit">发送意见</Button>
      </Col>
    </Row>

  </Card>
</template>
<script>
  export default {
    data() {
      return {
        loading: true,
        chushenLoading: true,
        fushenLoading: true,
        query: [],
        info: [],
        chushenColumns: [{
            align: 'center',
            type: 'selection',
            width: 60
          },
          {
            align: 'center',
            title: '序号',
            key: 'num',
            width: 80
          },
          {
            align: 'center',
            title: '初审意见',
            key: 'Audit_opinion'
          },
          {
            align: 'center',
            title: '修改说明',
            key: 'Revise_explain'
          },
        ],
        fushenColumns: [
          // {
          //   align: 'center',
          //   type: 'selection',
          //   width: 60
          // },
          {
            align: 'center',
            title: '序号',
            type: 'index',
            width: 80
          },
          {
            align: 'center',
            title: '复审意见',
            key: 'Audit_opinion',
            render: (h, {
              row,
              index
            }) => {
              return h('Input', {
                props: {
                  type: 'text',
                  value: row.Audit_opinion
                },
                on: {
                  'on-blur': (val) => {
                    this.info.Fushen[index].Audit_opinion = val.target.value
                  }
                }
              })
            }
          },
        ],
      }
    },
    mounted() {
      let query = this.$route.query
      this.query = query
      this.findByProject(query.Project_id, query.Atype)
    },
    methods: {
      inputAdd(type) {
        this.info[type].push({})
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      findByProject(Project_id, Atype) {
        axios.get('/audit/findByProject', {
          params: {
            Atype,
            Project_id
          }
        }).then(res => {
          this.info = res
          this.chushenLoading = false
          this.fushenLoading = false
          console.log(this.info)
        })
      },
      submit() {
        let query = this.query
        let AuditReplyLists = this.info.Fushen
        for (let val of AuditReplyLists) {
          val['Audit_id'] = query.id
          val['Audit_time'] = this.$moment().format('YYYY-MM-DD HH:mm:ss')
        }
        if (Object.keys(AuditReplyLists).length <= 0) {
          this.$Modal.error({
            title: '点击添加请输入意见'
          })
        } else {
          axios.get('/audit/isAuditb', {
            params: {
              Project_id: query.Project_id,
              Btype: query.Atype,
              OK: 1
            }
          }).then(res => {
            let title = res._MESSAGE
            if (res._STATUS == 1) {
              this.$Modal.success({
                title: title + ': 请进入正在进行项目人员提交'
              })
              axios.post('/auditreply/saveOrUpdateM', {
                AuditReplyLists,
              }).then(res => {

              }).catch(err => {
                this.$Modal.error({
                  title: '发送失败'
                })
              })
            } else {
              this.$Modal.error({
                title: title + '：等待业务人员提交'
              })
            }
          })

        }

      }
    },
  }
</script>

<style lang="less">
  #fushen {
    .ivu-input {
      border: none !important;
      height: 30px;

      input {
        outline: medium;
      }
    }

    .ivu-table-tip {
      overflow-x: hidden;
    }
  }
</style>